﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Waiter.Controler;
using Waiter.Common;

namespace Waiter.View
{
    public partial class FrmCouponDetials : DevComponents.DotNetBar.Office2007Form
    {
        public FrmCouponDetials()
        {
            InitializeComponent();
        }

        bool canShowFlag = true;

        public bool CanShowFlag
        {
            get { return canShowFlag; }
        }

        public FrmCouponDetials(string tableCode)
        {
            CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_INFO, "FrmCouponDetials.FrmCouponDetials", "", "");

            InitializeComponent();

            TableCtrl tableCtrl = new TableCtrl();
            TABLE item = tableCtrl.fsFindTableByCode(tableCode);
            if (item == null)
            {
                this.canShowFlag = false;
                return;
            }
            if (item.STATUS_CODE != (int)TableStatus.BUSY)
            {
                this.canShowFlag = false;
                return;
            }

            this.lblTableName.Text = "Bàn " + item.TABLE_NAME;
            fsLoadCouponDgr(tableCode);
        }

        private void fsLoadCouponDgr(string tableCode)
        {
            CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_INFO, "FrmCouponDetials.fsLoadCouponDgr", "", "");

            OrderCouponCtrl orderCouponCtrl = new OrderCouponCtrl();
            List<ORDER_COUPON_D> orderCouponList = orderCouponCtrl.fsGetCurrentOrderCouponList(tableCode);
            if (orderCouponList == null || orderCouponList.Count == 0)
            {
                this.canShowFlag = false;
                return;
            }

            this.dgrTableDetail.Rows.Add(orderCouponList.Count);
            int count = 0;
            long money = 0;
            for (int i = 0; i < orderCouponList.Count; i++)
            {
                dgrTableDetail.Rows[i].Cells["colName"].Value = orderCouponList[i].MENU.DRINKS_NAME;
                dgrTableDetail.Rows[i].Cells["colCount"].Value = orderCouponList[i].COUNT;
                dgrTableDetail.Rows[i].Cells["colMoney"].Value = orderCouponList[i].PRICE * orderCouponList[i].COUNT;
                count += (int)orderCouponList[i].COUNT;
                money += orderCouponList[i].PRICE * orderCouponList[i].COUNT;

                //if (orderCouponList[i].STATUS == (int)OrderCouponDStatus.NOT_PREPARED)
                //{
                //    dgrTableDetail.Rows[i].DefaultCellStyle.BackColor = Color.LightGray;
                //}
            }
            this.lblTotal.Text = count.ToString();
            this.lblMoney.Text = money.ToString("#,##0");
        }
    }
}
